#include <boost/extension/extension.hpp>
#include <PFileInfo.h>
#include <cstring>
#include "PDFConverter.h"

#ifdef _DEBUG
#include <iostream>
#endif
/* PDF Convert Plugin Entry Point
 * 
 * Predstavuje vstupny bod do dynamicky linked library.
 * Nato aby Konverzny modul vedel pracovat s toutou dll-kou
 * vsetky nasledujuce metody musia byt pristupne a implementovane.
 *
 */

//vytvorime globalny objekt ktory potom bude volany z prislusnich funkcii
Pdfcon::Converter pdfConverter;


extern "C"
bool BOOST_EXTENSION_EXPORT_DECL Open(PComunicator::PFileInfo &theFile)
{
	return pdfConverter.Open(theFile); 
}

extern "C"
char BOOST_EXTENSION_EXPORT_DECL *Format(void)
{
	return "pdf";
}

extern "C"
wchar_t BOOST_EXTENSION_EXPORT_DECL *Read(void) 
{
	std::wstring _res = pdfConverter.Read();
	wchar_t *result = new wchar_t[_res.size()];
	wcscpy(result,_res.c_str());	
	return result;
}


extern "C"
char BOOST_EXTENSION_EXPORT_DECL *CreateHtml(const char* thePath)
{
	std::string _ret = pdfConverter.CreateHtml(thePath);
#ifdef _DEBUG
	std::cout << _ret << std::endl;
#endif
	char *result = new char[_ret.size()];
	strcpy(result,_ret.c_str());
#ifdef _DEBUG
	std::cout << (*result) << std::endl;
#endif
	return result;
}


extern "C"
char BOOST_EXTENSION_EXPORT_DECL *Version(void)
{
	return "1.0";
}


extern "C"
char BOOST_EXTENSION_EXPORT_DECL *Autor(void)
{
	return "Marek Szanyi";
}